#include "widget.h"
#include "ui_widget.h"
#include <QRect>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    target_button=new QPushButton(this);
    QPushButton* left_button=new QPushButton(this);
    QPushButton* right_button=new QPushButton(this);
    target_button->setText("目标按钮");
    left_button->setText("向左移动");
    right_button->setText("向右移动");

    target_button->move(250,200);
    left_button->move(100,300);
    right_button->move(400,300);
    connect(left_button,&QPushButton::clicked,this,&Widget::left);
    connect(right_button,&QPushButton::clicked,this,&Widget::right);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::left()
{
    QRect tmp=target_button->geometry();
    tmp.setX(tmp.x()-15);
    qDebug()<<tmp;

//    target_button->setGeometry(tmp.x()-15,tmp.y(),tmp.width(),tmp.height());

    target_button->setGeometry(tmp);
}

void Widget::right()
{
    QRect tmp=target_button->geometry();
    tmp.setX(tmp.x()+15);
    qDebug()<<tmp;
//    target_button->setGeometry(tmp.x()+15,tmp.y(),tmp.width(),tmp.height());
    target_button->setGeometry(tmp);
}

